﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects;
using System.Data.Objects.DataClasses;

using LIM.model;

namespace LIM.controller
{
    public class CRM_PhieuNhanMauController : BaseController
    {
        public CRM_PhieuNhanMauController() { }
        public CRM_PhieuNhanMauController(LIMS_Entities LIMS_Entities)
        {
            this.LIMS_Entities = LIMS_Entities;
        }
        public void Refresh_MauDuocNhan(EntityCollection<tbl_CRM_PhieuNhanMau_MauDuocNhan> entities)
        {
            LIMS_Entities.Refresh(RefreshMode.StoreWins, entities);
        }

        public List<tbl_DanhMuc_ChiTieu> LoadChiTieu()
        {
            return LIMS_Entities.tbl_DanhMuc_ChiTieu.ToList();
        }
        public tbl_DanhMuc_ChiTieu LoadChiTieu_ByRowID(int RowIDChiTieu)
        {
            return LIMS_Entities.tbl_DanhMuc_ChiTieu.Where(p => p.RowID == RowIDChiTieu).FirstOrDefault();
        }
        
        public tbl_CRM_PhieuNhanMau loadPhieuNhanMauByID(int ID)
        {
            return LIMS_Entities.tbl_CRM_PhieuNhanMau.Where(p => p.RowID == ID).FirstOrDefault();
        }
        public List<v_PhieuNhanMau> LoadPhieuNhanMauByRowIDPhieuNhanMau(int RowIDPhieuNhanMau)
        {
            return LIMS_Entities.v_PhieuNhanMau.Where(p => p.RowIDPhieuNhanMau == RowIDPhieuNhanMau).ToList();
        }
        public string GetKH(int? RowIDKH)
        {
            string result = "";
            if (RowIDKH != null)
            {
                tbl_CRM_KhachHang a = LIMS_Entities.tbl_CRM_KhachHang.Where(p => p.RowID == RowIDKH).FirstOrDefault();
                if (a != null)
                {
                    result = a.TenGoi;
                }
            }
            return result;
        }
        public string GetLienHe(int? RowIDLienHe)
        {
            string result = "";
            if (RowIDLienHe != null)
            {
                tbl_CRM_LienHe a = LIMS_Entities.tbl_CRM_LienHe.Where(p => p.RowID == RowIDLienHe).FirstOrDefault();
                if (a != null)
                {
                    result = a.HoTen;
                }
            }
            return result;
        }

    }
}
